package com.darwin.darwinIsometric.map
{
	import com.darwin.darwinIsometric.core.IsoObject;
	import com.darwin.darwinIsometric.core.isoConst.IsoType;
	
	import flash.utils.Dictionary;

	/**
	 * 每个地图项的数据
	 * @author lipi
	 */
	public class IsoMapItem
	{
		public function IsoMapItem()
		{
			_dic = new Dictionary();
		}
		
		
		private var _dic:Dictionary;
		
		public var length:int = 0;
		
		
		/**
		 * 将一个isoObject对象添加到列表
		 */
		public function addIsoObject(isoObject:IsoObject):void
		{
			_dic[isoObject] = isoObject;
			length++;
			_walkableChange = true;
		}
		
		
		/**
		 * 从列表移除一个isoObject对象
		 */
		public function removeIsoObject(isoObject:IsoObject):void
		{
			if(_dic[isoObject] != null)
			{
				delete _dic[isoObject];
				length--;
				_walkableChange = true;
			}
		}
		
		
		/**
		 * 取得当前存储的对像
		 */
		internal function get objectDic():Dictionary
		{
			return _dic;
		}
		
		
		/**
		 * 外部设置的可能通行值
		 */
		private var _outWalkable:int = 1;
		
		/**
		 * 设置item的通行值
		 */
		public function setWalkable(value:int):void
		{
			_outWalkable = value;
			_walkableChange = true;
		}
		
		
		//可通行状态发生变化
		private var _walkableChange:Boolean = true;
		
		
		//可通行状态值
		private var _walkable:int = 1;
		
		/**
		 * 是否是可通过的
		 */
		public function get walkable():int
		{
			if(_walkableChange)
			{
				for(var name:Object in _dic)
				{
					if((_dic[name] as IsoObject).walkable == 0 ||  (_dic[name] as IsoObject).walkable>_walkable)
					{
						_walkable = (_dic[name] as IsoObject).walkable;
						if(_walkable == 0) return _walkable;
					}
				}
				if(_outWalkable == 0 || _outWalkable > _walkable)
				{
					_walkable = _outWalkable;
					if(_walkable == 0) return _walkable;
				}
			}
			return _walkable;
		}
		
		
	}
}